package com.tianqu.tms.www.transfer.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferAcceptedInfo;

public class SerialGroupSearchAjaxAction extends TmsAjaxAction {
	private Logger logger = Logger.getLogger(SerialGroupSearchAjaxAction.class);
	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		// 到系统功能配置表（tms_configure）获取参数名为gashGroup的值,确定分组
		String strGashGroup = Registry.getConfig(TmsConstants.GASH_GROUP);
		String[] gashGroup = strGashGroup.split("\\]\\[");
		
		TransferAcceptedInfo acceptedInfo = TransferAcceptedInfo.getInstance();

		String str = "";
		if (gashGroup != null && gashGroup.length > 0) {
			for (int i = 0; i < gashGroup.length; i++) {
				String linkContent = "";
				List<String> serialList = acceptedInfo.findListBySerial(gashGroup[i].replaceAll("\\[", "").replaceAll("\\]", "").split(","));
				
				if (i == 0) linkContent = "A组：流水号尾号是";
				if (i == 1) linkContent = "B组：流水号尾号是";
				if (i == 2)	linkContent = "C组：流水号尾号是";
				
				linkContent = linkContent + gashGroup[i].replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(",", "，")
								+ "的信息（待处理" + serialList.size()+ "笔）";
				
				if ("".equals(str)) {
					str = linkContent;
				} else {
					str = str + "," + linkContent;
				}
			}
		}
		
		responseValues(response, str, TEXT);
		logger.debug(this.getClass().getName() + "#execute was completed.");
	}
}
